package net.huashitong.Indicators.service;

import com.alibaba.fastjson.JSONArray;
import net.huashitong.Indicators.entity.UserInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserPressService {

    @Autowired
    private UserInfoService userService;


    /**
     * 获取不可看指标
     * @param openId
     * @return
     */
    public String  getHideCode(String openId)
    {

        UserInfo userInfo  = userService.getById(openId);
        String  codes  =userInfo.getNoRight();
        JSONArray array = JSONArray.parseArray(codes);
        StringBuffer sb = new StringBuffer();
        for (int i =0;i<array.size();i++ )
        {
            sb.append(",'"+array.get(i)+"'");
        }
        //sb.toString().substring(0);

        return sb.toString().substring(0);
    }

    /**
     * 获取不可看指标
     * @param openId
     * @return
     */
    public Map<String,String> getHideCodeList(String openId)
    {

        UserInfo userInfo  = userService.getById(openId);
        String  codes  =userInfo.getNoRight();
        if(StringUtils.isBlank(codes)){
            codes = "[]";
        }
        JSONArray array = JSONArray.parseArray(codes);
       // List<String> list  = new ArrayList<>();
        Map<String,String> map = new HashMap<>();
        for (int i =0;i<array.size();i++ )
        {
            map.put(array.get(i).toString(),array.get(i).toString());
        }
        //sb.toString().substring(0);
        return map;
    }

}
